package com.zr.planClass.controller;

import com.zr.planClass.model.StatusVo;
import com.zr.planClass.model.inquiry.*;
import com.zr.planClass.model.legalandperson.LegalPerson;
import com.zr.planClass.model.legalandperson.User;
import com.zr.planClass.service.InquiryService;
import com.zr.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 非常狂躁的猪 on 2019/12/26.
 */
@RestController
@CrossOrigin
public class InquiryController {

    @Autowired
    private InquiryService inquiryService;

    @PostMapping("inquiryList/search")
    public ResultVo inquiryList(@RequestBody InquiryQueryAllVo inquiryQueryAllVo){
        ResultVo resultVo = inquiryService.queryAllInquiry(inquiryQueryAllVo);
        //开始时间和结束时间还没有判断
        //必填的两个时间框还没有进行判断
        return resultVo;
    }

    @GetMapping("partner/queryByLegalPerson")
    public ResultVo queryByLegalPerson (Integer legalPersonId ){

        ResultVo resultVo = inquiryService.getPartner(legalPersonId);
        System.out.println();
        return resultVo;
    };

    @GetMapping("plan/getUser")
    public ResultVo getUser(){

        ResultVo resultVo = inquiryService.getUserDanHao();

        return resultVo;

    }

    @PostMapping("inquiryList/selectMaterial")
    public ResultVo selectMaterial(@RequestBody SpareQueryAllVo spareQueryAllVo){     //备件新增分页
        ResultVo resultVo = inquiryService.selectMaterial(spareQueryAllVo);
        return resultVo;
    }

    @PostMapping("procurement/getPullDownList") //下拉框
    public ResultVo getPullDownList(){
        Map<String,List> map = new HashMap<>();
        List<StatusVo> list2 = new ArrayList<>();
        for (TypeEnum t:TypeEnum.values() ){
            StatusVo statusVo = new StatusVo(t.getValue(),t.getName());
            list2.add(statusVo);
        }

        map.put("type",list2);

        List<StatusVo> list3 = new ArrayList<>();
        for (StatusEnum s:StatusEnum.values()){
            StatusVo statusVo = new StatusVo(s.getValue(),s.getName());
            list3.add(statusVo);
        }

        map.put("inquiryStatus",list3);

        List<StatusVo> list4 = new ArrayList<>();
        for (CurrencyCodeEnum c:CurrencyCodeEnum.values()){
            StatusVo statusVo = new StatusVo(c.getValue(),c.getName());
            list4.add(statusVo);
        }
        map.put("currencyCode",list4);

        List<StatusVo> list5 = new ArrayList<>();
        for (IsTaxEnum i:IsTaxEnum.values()){
            StatusVo statusVo = new StatusVo(i.getValue(),i.getName());
            list5.add(statusVo);
        }
        map.put("isTax",list5);

        List<StatusVo> list6 = new ArrayList<>();
        for (StatusEnum s:StatusEnum.values()){
            StatusVo statusVo = new StatusVo(s.getValue(),s.getName());
            list6.add(statusVo);
        }
        map.put("biddingStatus",list6);

        return ResultBuilderVo.success(map);
    }

    @PostMapping("material/searchPartnerPage")   //供应商新增分页
    public ResultVo searchPartnerPage(@RequestBody SupplierQueryVo supplierQueryVo){
        ResultVo resultVo = inquiryService.searchPartnerPage(supplierQueryVo);
        return resultVo;
    }

    @PostMapping("inquiryList/add")
    public ResultVo add(@RequestBody InquiryTotal inquiryTotal){
       /* System.out.println(inquiryTotal.getSupplierDetailsList());
        System.out.println(inquiryTotal.getInquiryDetailsList()); */
        ResultVo resultVo = inquiryService.add(inquiryTotal);
        return resultVo;
    }

    @PostMapping("inquirySheet/see")
    public ResultVo see(@RequestBody InquiryTotal inquiryTotal){

        ResultVo resultVo = inquiryService.see(inquiryTotal.getRequestForQuotationId());
        //System.out.println(resultVo.getData());
        return resultVo;
    }

    @PostMapping("inquiryList/update")
    public ResultVo update(@RequestBody InquiryTotal inquiryTotal ){

        ResultVo resultVo = inquiryService.update(inquiryTotal);

        return  resultVo;
    }

    @PostMapping("quotation/InquiryIntroduction")
    public ResultVo quotation(MultipartFile file) throws Exception{

        return inquiryService.quotation(file);
    }


}
